﻿using System;
using System.Collections.Generic;
using System.Text;


using CMN.Common;
using CMN.Entity;
using CMN.BLL;
using CMN.Cache;
using CMN.Extends;
using System.IO;
namespace CMN.Extends.Job
{
    public static  class CacheCollcetSet
    {
        public const string CacheCollcetSetKey = "CacheCollcetSetKey";

        public static List<Extend_CollectSetInfoEntity> CollectSetInfoList()
        {
            HttpWebCache cache = new HttpWebCache();
            List<Extend_CollectSetInfoEntity> czflList = new List<Extend_CollectSetInfoEntity>();
            if (cache[CacheCollcetSetKey] == null)
            {
                 int recordCount = 0;
                    QueryParam qp = new QueryParam();
                    qp.PageSize = 10000;
                    //qp.Where = "Enabled=1";
                try
                {
                   
                    Extend_CollectSetInfo bll = new Extend_CollectSetInfo();
                    czflList = bll.List(qp, out recordCount);
                    cache.Insert(CacheCollcetSetKey, czflList ,3000);

                }
                catch (Exception ex)
                {
                    AppLog.Write("CollectSetInfoList错误:" +qp.PageSize.ToString()+ qp.Where, AppLog.LogMessageType.Error, ex);
                }
            }
            else
                czflList = (List<Extend_CollectSetInfoEntity>)cache[CacheCollcetSetKey];
            return czflList;
        }

        public static Extend_CollectSetInfoEntity GetSetInfo(int id)
        {
            Extend_CollectSetInfoEntity setInfo = null;
            List<Extend_CollectSetInfoEntity> czflList = CollectSetInfoList();
            foreach (Extend_CollectSetInfoEntity info in czflList)
            {
                if (info.Id == id)
                {
                    setInfo = info;
                    break;
                }
            }
            return setInfo;
        }

        public static void ClearCache()
        {
            HttpWebCache cache = new HttpWebCache();
            cache.Remove(CacheCollcetSetKey);
        }
    }
}
